<script setup lang="ts" >
const name = "template"
import {ref, onMounted, toRefs, nextTick , onBeforeMount} from "vue"
import {usePiniaStore} from "@/store"
import My from "@/views/my/My.vue"
import i18n from "@/lang/i18n";
import { useI18n } from 'vue-i18n';
const { locale, t } = useI18n();

import {changeLangUtil,initMyLangUtil} from "@/utils/langguageUtils";


import {
  Document,
  Menu ,
  Location,
  Setting,
} from '@element-plus/icons-vue'

const isCollapse = ref(true)
const handleOpen = (key: string, keyPath: string[]) => {
  console.log('22222222')
  console.log(key, keyPath)
}
const handleClose = (key: string, keyPath: string[]) => {
  console.log('11111111111')
  console.log(key, keyPath)
}


// 2 拿到实例
const piniaStore = usePiniaStore();
// 3 解构里面的变量和方法 toRefs作用是让解构出来的变量具有响应性
const { num, changeNum } = toRefs(piniaStore);


onMounted(() => {
  // console.log('_______,onMounted')
  initMyLangUtil()
})


const myDialog = ref<Boolean>(false)


const asideBtnClick = () => {
  isCollapse.value = !isCollapse.value
  console.log('__________')

}

/**
 *
 */
const aboutClick = () => {
  myDialog.value = true
}

/**
 * 退出登录
 */
const logout = () => {
  piniaStore.logout()
}



/**
 * 修改语言
 */
const changeLang = (language : any) => {

  changeLangUtil(language)
}

</script>

<template>
  <el-container class="container">
    <div class="aside">
      <el-menu default-active="2"
               :collapse="isCollapse"
               @open="handleOpen"
               @close="handleClose"
               :router="true">
        <el-sub-menu index="1">
          <template #title>
            <el-icon>
              <location />
            </el-icon>
            <span>{{i18n.global.t('component')}}</span>
          </template>
          <el-menu-item-group>
            <template #title>{{i18n.global.t('component')}}</template>
            <el-menu-item index="/">{{i18n.global.t('cart')}}</el-menu-item>
            <el-menu-item index="/">{{i18n.global.t('cart')}}</el-menu-item>
          </el-menu-item-group>
        </el-sub-menu>
        <el-menu-item index="md">
          <el-icon>
            <document />
          </el-icon>
          <template #title>markdown</template>
        </el-menu-item>
        <el-menu-item index="mock">
          <el-icon>
            <document />
          </el-icon>
          <template #title>{{i18n.global.t('mockData')}}</template>
        </el-menu-item>
      </el-menu>
    </div>
    <el-container>
      <el-header class="header">
        <div class="asideBtn">
          <el-button @click="asideBtnClick" size="large"  circle :icon="Menu" ></el-button>
        </div>
        <div class="title">
          {{i18n.global.t('title')}}
        </div>
        <div class="aboutMeBtn">
          <el-dropdown>
            <el-button type="primary">
              {{i18n.global.t('language')}}
            </el-button>
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="changeLang('zh')">中文</el-dropdown-item>
                <el-dropdown-item @click="changeLang('en')">English</el-dropdown-item>
                <el-dropdown-item @click="changeLang('ug')">ئۇيغۇر تىلى</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
          <el-dropdown split-button type="primary" @click="aboutClick">
            {{i18n.global.t('aboutMe')}}
            <template #dropdown>
              <el-dropdown-menu>
                <el-dropdown-item @click="aboutClick">{{i18n.global.t('aboutMe')}}</el-dropdown-item>
                <el-dropdown-item @click="logout">{{i18n.global.t('logout')}}</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </div>
      </el-header>
      <el-main class="main">

        <div class="content">
          <router-view />
        </div>
      </el-main>
      <el-footer class="footer">
        <div class="aboutMe">
          {{i18n.global.t('powerdByMe')}}
        </div>
      </el-footer>
    </el-container>
  </el-container>
  <div class="other">
    <el-dialog
        v-model="myDialog"
    >
      <My />
      <!--      <template #footer>-->
      <!--      <span class="dialog-footer">-->
      <!--        <el-button @click="dialogVisible = false">Cancel</el-button>-->
      <!--        <el-button type="primary" @click="dialogVisible = false">-->
      <!--          Confirm-->
      <!--        </el-button>-->
      <!--      </span>-->
      <!--      </template>-->
    </el-dialog>
  </div>
</template>

<style scoped lang="scss">
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-footer{
  padding: 0;
}

.container {
  height: 100vh;
  width: 100vw;

  .header {
    padding: 0;
    background-color: #B3C0D1;
    color: #333;
    display: flex;
    text-align: center;

    .asideBtn{
      line-height: 60px;
      margin-left: 5px;
      width: 50px;
    }

    .title{
      margin: auto;
      color: slategrey;
      font-size: 1.6em;
    }

    .aboutMeBtn{
      *{
        margin: 0 5px;
      }
      margin: auto 0;
      margin-right: 25px;
    }
  }

  .main {
    background-color: #E9EEF3;
    color: #333;
    display: flex;
    padding: 25px;

    .content {
      //background-color: cornflowerblue;
      width: 100%;
      border-radius: 5px;
      overflow: scroll;
      height: calc(100vh - 170px);
    }
  }

  .footer {
    display: flex;
    background-color: #B3C0D1;
    color: #333;
    justify-content: center;
    align-items: center;

    .aboutMe{
      text-align: center;
      color: slategrey;
      transform:scale(0.8,0.8)
    }

  }

}
</style>